package com.demo.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.SQLQuery;
import org.springframework.stereotype.Component;

import com.demo.dao.UserDao;
import com.demo.model.User;
@Component("userDao")
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao{

	@Override
	public User getInfoBySql(String sql,List<String> params) {
		List<User> list=new ArrayList<User>();
		User user=null;
		SQLQuery sqlquery=getSession().createSQLQuery(sql);
		if(params!=null){
			for (int i=0;i<params.size();i++) {
				sqlquery.setString(i,params.get(i));
			}
		}
		sqlquery.addEntity(User.class);
		list=sqlquery.list();
		if(list!=null&&list.size()>0){
			user=list.get(0);
		}
		return user;
	}

	@Override
	public List<User> getListBySql(String sql) {
		List<User> list=new ArrayList<User>();
		SQLQuery sqlquery=getSession().createSQLQuery(sql);
		sqlquery.addEntity(User.class);
		list=sqlquery.list();	
		return list;
	}

}
